// ----------------------------------------------------------------------------
/**
 * @file    ClientInformation.h
 *
 * @brief   Header file for clientInformation.cpp
 *
 * Container class for the user including socket, friends list, and other information.
 *
 * @author  Siddharth Sathyam <ssathy2@gmail.com>
 * @author  Alan Ruvalcaba <aruval3@gmail.com>
 * @author  Patrick LaMontagna <plamontagna@gmail.com
 *
 * @version 1.0
 *
 * @date    November 24th, 2011
 *
 */
// ----------------------------------------------------------------------------

#ifndef CLIENTINFORMATION_H
#define CLIENTINFORMATION_H

#include <QList>
#include <QTcpSocket>
#include <QStringList>
#include <QObject>

/**
 * @class   clientInformation
 *
 * @brief   Client helper methods
 *
 * Container class for the user including socket, friends list, and other information.
 */

class clientInformation: public QObject
{
Q_OBJECT
    public:
        /// Constructor with name and socket
	clientInformation(QString name, QTcpSocket* socket);

        /// Constructor with name and friendsList
	clientInformation(QString name, QStringList friendsList);

        /**
        * @brief Updates the current socket to a new socket
        *
        * @param sockToUpdateTo The QTcpSocket to update
        */

	void updateSocket(QTcpSocket* sockToUpdateTo);

        /**
        * @brief Sends a list of friends online
        *
        * @param serverUsersOnline The QList of users online
        */

	void sendOnlineFriendsList(QList<QString> serverUsersOnline);

        /// getSocket method
        /// @return A QTcpSocket being used
	QTcpSocket* getSocket();

        /// getUserName method
        /// @return A QString username being used
	QString getUserName();

	/**
        * @brief Sends message passed in to the person in the parameters with the time the message was sent at.
	*
        * @param personThatSentMessage The QString of the user that the message was sent from
        * @param message The QString of the user that the message is going to be sent to
        * @param timeSentAt The time the message was sent
        * @return A boolean value indicating whether or not the message was successfully sent
	*/

	bool sendMessage(QString personThatSentMessage, QString message, QString timeSentAt);

	/**
        * @brief Adds the parameter user to the friends list of this user
	*
	* @param buddy clientInformation object of the user to add as a friend to this user
        * @return A boolean value indicating whether or not the addition was successfully or not
	*/

	bool addToFriendsList(clientInformation* buddy);

	/**
        * @brief Removes the parameter user to the friends list of this user
	*
	* @param nonFriend clientInformation object of the user to remove as a friend to this user
        * @return A boolean value indicating whether or not the addition was successfully or not
	*/

	bool removeFromFriendsList(clientInformation* nonFriend);

	/**
        * @brief Checks whether or not the parameter friend is in the friends list of this user
	*
	* @param user QString name of user to check if it exists in the friend's list
        * @return A boolean value indicating whether or not the user exists or not
	*/

	bool isUserFriend(QString user);

    public slots:
	/**
        * @brief Slot to handle the signal from removing a friend
	*
	* @param personSendingRequest clientInformation object of the user to to remove
        * @param isValid boolean value indicating if this remove operation is valid or not
	*/

	void handleRemoveFriend(clientInformation* personSendingRequest, bool isValid);

	/**
        * @brief Slot to handle the signal from whether or not a valid remove friend request wsa sent
	*
	* @param personToRemove clientInformation object of the user to to remove
        * @param isValid boolean value indicating if this remove operation is valid or not
	*/

	void handleIsValidRemoveFriend(QString personToRemove, bool isValid);

	/**
        * @brief Slot to handle the signal from adding a friend. The object that calls this slot is the user that the request is sent to
	*
	* @param personSendingRequest QString name of the person that sent the add friend request
	*/

	void handleAddFriend(QString personSendingRequest);

	/**
        * @brief Slot to handle the signal from checking if the friend request that was sent is valid or not.
	*
        * @param personToAdd QString name of the person that sent the add friend request
        * @param isValid boolean value indicating if the request was valid or not
	*/

	void handleIsValidFriendRequest(QString personToAdd, bool isValid);

	/**
        * @brief Slot to handle the signal from a friend acceptance. The user that calls this slot is the user that is recieving the friend acceptance
	*
	* @param sentUser clientInformation object of the person that sent the add friend request
        * @param isAccepted boolean value indicating if the request was accepted or not
	*/

	void handleFriendAcceptance(clientInformation* sentUser, bool isAccepted);

        /**
        * @brief Slot to handle the signal from a sent message. The user that calls this slot is the user that is sending the message
        *
        * @param fromUser The from user
        * @param toUser The to user
        * @param message The message being sent
        * @param timeSent The time the message was sent
        */

	void handleSendMessage(QString fromUser, QString toUser, QString message, QString timeSent);

    private:

        /**
        * @brief StringList that contains the individual strings of the friends of this user
        */

	QStringList stringListOfFriends;

        /**
        * @brief Table that contains the name of the user and its corresponding clientInformation object pointer
        */

	QHash<QString, clientInformation*> tableOfFriends;

        /**
        * @brief Username of this person
        */

	QString userName;

        /**
        * @brief TcpSocket used in order to talk to the user
        */

	QTcpSocket* sock;
};

#endif // CLIENTINFORMATION_H
